API: Require passing a GLContext to begin_draw_frame()
authorBenjamin Otte <otte@redhat.com>
Tue, 22 Nov 2016 03:12:51 +0000 (04:12 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 5 Dec 2016 14:02:47 +0000 (15:02 +0100)
This is in preparation for requiring explicit passing of GL contexts
when drawing.

gdk/gdkdrawingcontext.c
gdk/gdkdrawingcontext.h
gdk/gdkwindow.c
gdk/gdkwindow.h
gtk/gtkwidget.c

index cee0ea9cda473af036b1f1fef388a78fcd913ad0..ec230a13c9d784031505ab6a1041f784746b851c 100644 (file)
@@ -63,6 +63,7 @@ enum {
 
   PROP_WINDOW,
   PROP_CLIP,
+  PROP_PAINT_CONTEXT,
 
   N_PROPS
 };
@@ -110,9 +111,9 @@ gdk_drawing_context_set_property (GObject      *gobject,
                       G_OBJECT_TYPE_NAME (gobject));
           return;
         }
-      priv->paint_context = priv->window->gl_paint_context;
-      if (priv->paint_context)
-        g_object_ref (priv->paint_context);
+
+    case PROP_PAINT_CONTEXT:
+      priv->paint_context = g_value_dup_object (value);
       break;
 
     case PROP_CLIP:
@@ -143,6 +144,10 @@ gdk_drawing_context_get_property (GObject    *gobject,
       g_value_set_boxed (value, priv->clip);
       break;
 
+    case PROP_PAINT_CONTEXT:
+      g_value_set_object (value, priv->paint_context);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
     }
@@ -183,6 +188,19 @@ gdk_drawing_context_class_init (GdkDrawingContextClass *klass)
                         G_PARAM_CONSTRUCT_ONLY |
                         G_PARAM_READWRITE |
                         G_PARAM_STATIC_STRINGS);
+  /**
+   * GdkDrawingContext:paint-context:
+   *
+   * The #GdkGLContext used to draw or %NULL if Cairo is used.
+   *
+   * Since: 3.90
+   */
+  obj_property[PROP_PAINT_CONTEXT] =
+    g_param_spec_object ("paint-context", "Paint context", "The context used to draw",
+                         GDK_TYPE_GL_CONTEXT,
+                         G_PARAM_CONSTRUCT_ONLY |
+                         G_PARAM_READWRITE |
+                         G_PARAM_STATIC_STRINGS);
 
   g_object_class_install_properties (gobject_class, N_PROPS, obj_property);
 }
@@ -287,6 +305,26 @@ gdk_drawing_context_get_window (GdkDrawingContext *context)
   return priv->window;
 }
 
+/**
+ * gdk_drawing_context_get_paint_context:
+ * @context: a #GdkDrawingContext
+ *
+ * Retrieves the paint context used to draw with.
+ *
+ * Returns: (transfer none): a #GdkGLContext or %NULL
+ *
+ * Since: 3.90
+ */
+GdkGLContext *
+gdk_drawing_context_get_paint_context (GdkDrawingContext *context)
+{
+  GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (context);
+
+  g_return_val_if_fail (GDK_IS_DRAWING_CONTEXT (context), NULL);
+
+  return priv->paint_context;
+}
+
 /**
  * gdk_drawing_context_get_clip:
  * @context: a #GdkDrawingContext
index d754fce79d9c90ec33fc05c94e34184c7dc77dfb..4f9980f90ba5a8c5624ce97d0af42842b01702c1 100644 (file)
@@ -38,6 +38,8 @@ GType gdk_drawing_context_get_type (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_3_22
 GdkWindow *     gdk_drawing_context_get_window          (GdkDrawingContext *context);
+GDK_AVAILABLE_IN_3_90
+GdkGLContext*   gdk_drawing_context_get_paint_context   (GdkDrawingContext *context);
 GDK_AVAILABLE_IN_3_22
 cairo_region_t *gdk_drawing_context_get_clip            (GdkDrawingContext *context);
 
index 86fb75609673729b34b8dc87922c4eefdd311d56..b70b3e5f76d39f3b2fdb2ab03dc96da4688b80c2 100644 (file)
@@ -2856,6 +2856,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
 /**
  * gdk_window_begin_draw_frame:
  * @window: a #GdkWindow
+ * @context: (allow-none): the context used to draw the frame
  * @region: a Cairo region
  *
  * Indicates that you are beginning the process of redrawing @region
@@ -2894,6 +2895,7 @@ gdk_window_end_paint_internal (GdkWindow *window)
  */
 GdkDrawingContext *
 gdk_window_begin_draw_frame (GdkWindow            *window,
+                             GdkGLContext         *gl_context,
                              const cairo_region_t *region)
 {
   GdkDrawingContext *context;
@@ -2901,6 +2903,11 @@ gdk_window_begin_draw_frame (GdkWindow            *window,
   g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
   g_return_val_if_fail (gdk_window_has_native (window), NULL);
   g_return_val_if_fail (gdk_window_is_toplevel (window), NULL);
+  if (gl_context != NULL)
+    {
+      g_return_val_if_fail (GDK_IS_GL_CONTEXT (gl_context), NULL);
+      g_return_val_if_fail (gdk_gl_context_get_window (gl_context) == window, NULL);
+    }
 
   if (window->drawing_context != NULL)
     {
@@ -2912,6 +2919,7 @@ gdk_window_begin_draw_frame (GdkWindow            *window,
 
   context = g_object_new (GDK_TYPE_DRAWING_CONTEXT,
                           "window", window,
+                          "paint-context", gl_context,
                           "clip", region,
                           NULL);
 
index 5a0601c9f53e2498c8cc7ff56f6527f0d9f31487..96d326ca7c6cc3c74a7e4fc46f1ce8a87f0689ea 100644 (file)
@@ -626,8 +626,9 @@ GDK_AVAILABLE_IN_3_16
 void         gdk_window_mark_paint_from_clip (GdkWindow          *window,
                                               cairo_t            *cr);
 
-GDK_AVAILABLE_IN_3_22
+GDK_AVAILABLE_IN_3_90
 GdkDrawingContext *gdk_window_begin_draw_frame  (GdkWindow            *window,
+                                                 GdkGLContext         *context,
                                                  const cairo_region_t *region);
 GDK_AVAILABLE_IN_3_22
 void          gdk_window_end_draw_frame    (GdkWindow            *window,
index 9f212fe430c22936fcebc7fd78b988dca5c5ff2b..641726dcb6364234bb03a350dd8ed34e50290d33 100644 (file)
@@ -15694,7 +15694,7 @@ gtk_widget_render (GtkWidget            *widget,
 
   gtk_inspector_record_render (widget, renderer, window, region, root);
 
-  context = gdk_window_begin_draw_frame (window, region);
+  context = gdk_window_begin_draw_frame (window, NULL, region);
 
   gsk_renderer_render (renderer, root, context);
   gsk_render_node_unref (root);